<template>
  <div>
    <el-form ref="form" :rules="rules" :model="form">
      <el-form-item :model="form" prop="goods_ico" label="商品图片">
        <el-input class="input3" v-model="phones.goods_ico" />
      </el-form-item>
      <el-form-item :model="form" prop="goods_name" label="商品名称">
        <el-input class="input1" v-model="phones.goods_name" />
      </el-form-item>

      <el-form-item prop="goods_price" label="商品价格">
        <el-input class="input2" v-model="phones.goods_price" />
      </el-form-item>
      <el-button @click="onsubmit" type="primary">确认修改</el-button>
    </el-form>
  </div>
</template>

<script>
import { Input } from 'element-ui'

export default {
  data() {
    return {
      // goods_name: '',
      // goods_price: '',
      // goods_ico: '',

      phones: [],
      form: {},
      rules: {
        goods_name: [
          {
            required: true,
            message: '必填',
            trigger: 'blur',
          },
        ],
        goods_price: [
          {
            required: true,
            message: '必填',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  methods: {
    onsubmit() {
      let params = {
        id: this.phones.id,
        goods_name: this.phones.goods_name,
        goods_price: this.phones.goods_price,
        goods_ico: this.phones.goods_ico,
        // goods_ico: this.form.cover,
      }
      this.$http.goodsApi.getRmGood(params).then(res => {
        console.log(params)
        console.log(res)
        if (res.data.code == 200) {
          alert('修改商品成功')
          this.phones = ''
        } else {
          alert('修改商品失败')
        }
      })
    },
  },
  mounted() {
    // 加载根据ID查询到的商品
    let id = this.$route.params.id
    this.$http.goodsApi.getIdGood(id).then(res => {
      console.log('商品信息', res)
      this.phones = res.data.data
      console.log(this.phones.goods_name)
    })
  },
}
</script>

<style lang="scss" scoped></style>
